package com.kedou.sdk.core;

import android.text.TextUtils;

import com.kedou.sdk.JuHaoWanSDK;
import com.kedou.sdk.JuHaoWanSDKConfiguration;
import com.kedou.sdk.handler.SimpleAsyncResponseHandler;
import com.kedou.sdk.params.AccountInfosRequestParams;
import com.kedou.sdk.params.AccountInfosTokenRequestParams;
import com.kedou.sdk.params.ActivityRequestParams;
import com.kedou.sdk.params.AgreementRequestParams;
import com.kedou.sdk.params.AlipayAuthRequestParams;
import com.kedou.sdk.params.AlipayRealnameParams;
import com.kedou.sdk.params.AuthLoginRequestParams;
import com.kedou.sdk.params.BindPhoneReuqestParams;
import com.kedou.sdk.params.BoxLoginRequestParams;
import com.kedou.sdk.params.CheckOrderRequestParams;
import com.kedou.sdk.params.CheckVersionRequestParams;
import com.kedou.sdk.params.ConfigInfoRequestParams;
import com.kedou.sdk.params.CreateOrderRequestParams;
import com.kedou.sdk.params.CreatePlatformOrderRequestParams;
import com.kedou.sdk.params.CreateSmallAccountRequestParams;
import com.kedou.sdk.params.GetRequestParams;
import com.kedou.sdk.params.LoginPhoneRequestParams;
import com.kedou.sdk.params.LoginRequestParams;
import com.kedou.sdk.params.LogoutRequestParams;
import com.kedou.sdk.params.ModifyPasswordReuqestParams;
import com.kedou.sdk.params.PayChannelReuqestParams;
import com.kedou.sdk.params.PlatformCoinDetailParams;
import com.kedou.sdk.params.PlatformCoinRequestParams;
import com.kedou.sdk.params.PushInfoRequestParams;
import com.kedou.sdk.params.QuickRegisterRequestParams;
import com.kedou.sdk.params.RealNameReuqestParams;
import com.kedou.sdk.params.RedpacakgeBindReuqestParams;
import com.kedou.sdk.params.RedpacakgeCashOutReuqestParams;
import com.kedou.sdk.params.RedpacakgeGetReuqestParams;
import com.kedou.sdk.params.RedpacakgeReuqestParams;
import com.kedou.sdk.params.RegisterRequestParams;
import com.kedou.sdk.params.RewardVideoRequestParams;
import com.kedou.sdk.params.RoleInfoRequestParams;
import com.kedou.sdk.params.SendVerifyReuqestParams;
import com.kedou.sdk.params.TencentLoginRequestParams;
import com.kedou.sdk.params.UuidRequestParams;
import com.kedou.sdk.params.bean.Goods;
import com.kedou.sdk.params.bean.NavModel;
import com.kedou.sdk.params.bean.RoleInfo;
import com.kedou.sdk.params.bean.RoleStatus;
import com.kedou.sdk.system.DeviceInfo;
import com.kedou.sdk.utils.AndroidDeviceGenerator;
import com.kedou.sdk.utils.WL;
import com.kedou.sdk.utils.XmlUtils;

/**
 * Created by Administrator on 2017/6/9 0009.
 */

public final class HttpEngineApi {

    private static final String TAG = HttpEngineApi.class.getSimpleName();

    private volatile static HttpEngineApi instance;
    private HttpEngineConduits engineConduits;

    JuHaoWanSDKConfiguration configuration;

    HttpEngine httpEngine;

    public static HttpEngineApi getInstance() {
        if (instance == null) {
            synchronized (HttpEngine.class) {
                if (instance == null) {
                    instance = new HttpEngineApi();
                }
            }
        }
        return instance;
    }

    public synchronized void init(JuHaoWanSDKConfiguration configuration) {
        if (configuration == null) {
            throw new IllegalArgumentException("HttpEngineApi configuration can not be initialized with null");
        }

        if (this.configuration == null) {
            this.configuration = configuration;
        } else {
            WL.w(TAG, "Try to initialize HttpEngineApi which had already been initialized before. To re-init HttpEngineApi with new configuration call HttpEngineApi.destroy() at first.");
        }

        if (httpEngine == null) {
            httpEngine = new HttpEngine(configuration.getThreadPoolSize());
        } else {
            WL.w(TAG, "Try to initialize HttpEngineApi which had already been initialized before. To re-init HttpEngineApi with new configuration call HttpEngineApi.destroy() at first.");
        }

        engineConduits = new HttpEngineConduits(configuration.getApplicationContext());
        engineConduits.saveGameId(configuration.getGameId());
    }

    public synchronized void destroy() {
        if (this.configuration != null) {
            this.configuration = null;
            WL.d(TAG, "Destroy HttpEngine configuration");
        }

        if (httpEngine != null && !httpEngine.isShutdown()) {
            httpEngine.shutdown();
            httpEngine = null;
        }
    }

    private String getBaseHttpPostUrl(){
        return XmlUtils.getPlatformPostUrl();
    }

    private String getBaseHttpGetUrl(){
//        return XmlUtils.getPlatformGetUrl();
        return engineConduits.getPlatformConfigInfo().getFloating_ur();
    }

    public void cancel(int taskId) {
        if (httpEngine != null) {
            httpEngine.cancelTask(taskId);
        }
    }

    public boolean isLoggedIn() {
        return engineConduits == null ? false : engineConduits.isLoggedIn();
    }

    static class HttpEngineInitializeException extends RuntimeException {
        public HttpEngineInitializeException(String message) {
            super(message);
        }
    }

    void checkEngineInitialization() {
        if (httpEngine == null || httpEngine.isShutdown() || configuration == null) {
            throw new HttpEngineInitializeException("The HTTP engine is not initialized.");
        }
    }

    public HttpEngineConduits getEngineConduits() {
        return engineConduits;
    }

    public int getAgreement(SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        AgreementRequestParams params = new AgreementRequestParams(configuration.getGameId());


        return httpEngine.getAgreement(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }


    public int getPlatformConfig(SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        ConfigInfoRequestParams params = new ConfigInfoRequestParams(configuration.getGameId(),
                AndroidDeviceGenerator.getDeviceID(configuration.getApplicationContext()));

        HttpEngineConduits conduits = HttpEngineApi.getInstance().getEngineConduits();
        if(!TextUtils.isEmpty(conduits.readCurrentOaid())){
            params.setOa_id(conduits.readCurrentOaid());
        }
        params.setAvail_memory(AndroidDeviceGenerator.getAvailMemory(configuration.getApplicationContext()));
        params.setTotal_memory(AndroidDeviceGenerator.getTotalMemory(configuration.getApplicationContext()));
        params.setImei(AndroidDeviceGenerator.getIMEI(configuration.getApplicationContext()));
//        params.setImei(DeviceIdentifier.getAndroidID(configuration.getApplicationContext()));
        params.setBrand(android.os.Build.BRAND);
        params.setModel(android.os.Build.MODEL);
        params.setMac_address(AndroidDeviceGenerator.getMacAddress(configuration.getApplicationContext()));
        params.setSystem_version(android.os.Build.VERSION.RELEASE);
        return httpEngine.getPlatformConfig(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int getAccountInfosByPhone(String phone, String verify, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        AccountInfosRequestParams params = new AccountInfosRequestParams(phone, verify);
        params.setGameId(configuration.getGameId());

        return httpEngine.getAccountInfosByPhone(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int getAccountInfosByToken( SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        AccountInfosTokenRequestParams params = new AccountInfosTokenRequestParams();
        params.setGameId(configuration.getGameId());

        return httpEngine.getAccountInfosByToken(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int authCodeLoginToken(String code, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        AuthLoginRequestParams params =new AuthLoginRequestParams();
        params.setToken(code);
        params.setGameId(configuration.getGameId());
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int createSmallAccount(String code, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        CreateSmallAccountRequestParams params =new CreateSmallAccountRequestParams();
        params.setName(code);
        params.setGameId(configuration.getGameId());
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }



    public int txOnekeyLogin(String token, String carrir, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        TencentLoginRequestParams params = new TencentLoginRequestParams(token, carrir);
        params.setGameId(configuration.getGameId());

        return httpEngine.tencentLogin(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int getUuid( SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        UuidRequestParams params = new UuidRequestParams();
        params.setGameId(configuration.getGameId());

        return httpEngine.getUuid(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int loginByVerify(String username, String verify, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        LoginPhoneRequestParams params = new LoginPhoneRequestParams(username, verify);
//        params.setCode("1");
//        params.setLogin_type(2);
//        params.setVerify(verify);
        params.setGameId(configuration.getGameId());
//        params.setAllApp(DeviceInfo.getAllApp(configuration.getApplicationContext()));
//        params.setMacAddress(DeviceInfo.getMacAddress(configuration.getApplicationContext()));
//        params.setAvailMemory(DeviceInfo.getAvailMemory(configuration.getApplicationContext()));
//        params.setTotalMemory(DeviceInfo.getTotalMemory(configuration.getApplicationContext()));
//        params.setCpuName(DeviceInfo.getCpuName());
//        params.setCurCpuFreq(DeviceInfo.getCurCpuFreq());
//        params.setMaxCpuFreq(DeviceInfo.getMaxCpuFreq());
//        params.setMinCpuFre(DeviceInfo.getMinCpuFreq());
//        params.setBrand(android.os.Build.BRAND);
//        params.setModel(android.os.Build.MODEL);
//
//        if (ToolsUtils.checkAppSelfPermission(configuration.getApplicationContext(), Manifest.permission.READ_PHONE_STATE)) {
//            params.setSimOperatorName(AndroidDeviceGenerator.getSimOperatorName(configuration.getApplicationContext()));
//            params.setImei(AndroidDeviceGenerator.getAndroidDeviceId(configuration.getApplicationContext()));
//            params.setImsi(AndroidDeviceGenerator.getSubscriberId(configuration.getApplicationContext()));
//            params.setLine1Number(AndroidDeviceGenerator.getLine1Number(configuration.getApplicationContext()));
//            params.setUuid(AndroidDeviceGenerator.generateAndroidDeviceUUID(configuration.getApplicationContext()));
//        }

        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }



    /**
     * 登录接口
     * @param username 登录帐号名称
     * @param password 如果为自动登录，即isAutoLogin参数为true，密码需要为上一次登录返回结果的password加密数据

     * @param handler
     * @return
     */
    public int login(String username, String password, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        LoginRequestParams params = new LoginRequestParams(username, password);

        params.setGameId(configuration.getGameId());
//        params.setAllApp(DeviceInfo.getAllApp(configuration.getApplicationContext()));
//        params.setMacAddress(DeviceInfo.getMacAddress(configuration.getApplicationContext()));



        return httpEngine.login(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }


    public int xiaohaologin(String code, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        BoxLoginRequestParams params = new BoxLoginRequestParams(code);

        params.setGameId(configuration.getGameId());
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }


    public int quickRegister(SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        QuickRegisterRequestParams params = new QuickRegisterRequestParams();
        params.setRegister_type(1);
        params.setGameId(configuration.getGameId());
//        params.setAllApp(DeviceInfo.getAllApp(configuration.getApplicationContext()));
//        params.setMacAddress(DeviceInfo.getMacAddress(configuration.getApplicationContext()));
        params.setAvailMemory(DeviceInfo.getAvailMemory(configuration.getApplicationContext()));
        params.setTotalMemory(DeviceInfo.getTotalMemory(configuration.getApplicationContext()));

        params.setCpuName(DeviceInfo.getCpuName());
        params.setCurCpuFreq(DeviceInfo.getCurCpuFreq());
        params.setMaxCpuFreq(DeviceInfo.getMaxCpuFreq());
        params.setMinCpuFre(DeviceInfo.getMinCpuFreq());
        params.setBrand(android.os.Build.BRAND);
        params.setModel(android.os.Build.MODEL);


//        if (ToolsUtils.checkAppSelfPermission(configuration.getApplicationContext(), Manifest.permission.READ_PHONE_STATE)) {
//            params.setSimOperatorName(AndroidDeviceGenerator.getSimOperatorName(configuration.getApplicationContext()));
//            params.setImei(AndroidDeviceGenerator.getAndroidDeviceId(configuration.getApplicationContext()));
//            params.setImsi(AndroidDeviceGenerator.getSubscriberId(configuration.getApplicationContext()));
//            params.setLine1Number(AndroidDeviceGenerator.getLine1Number(configuration.getApplicationContext()));
//            params.setUuid(AndroidDeviceGenerator.generateAndroidDeviceUUID(configuration.getApplicationContext()));
//        }
//        params.setIsRoot(CheckRoot.isDeviceRooted()?"true":"false");

        return httpEngine.quickRegister(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int register(String username, String password, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        RegisterRequestParams params = new RegisterRequestParams(username, password);
        params.setGameId(configuration.getGameId());
        params.setPlacement_platform_appid(JuHaoWanSDK.getInstance().getToutiaoAppid());
        return httpEngine.register(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int register(String username, String password,String code, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        RegisterRequestParams params = new RegisterRequestParams(username, password);
        params.setGameId(configuration.getGameId());
        params.setCode(code);
        params.setPattern("mobile");
        params.setPlacement_platform_appid(JuHaoWanSDK.getInstance().getToutiaoAppid());
        return httpEngine.register(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }


    public int logout(SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        LogoutRequestParams params = new LogoutRequestParams();

        params.setGameId(configuration.getGameId());

        httpEngine.logout(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
        engineConduits.isLoggedIn = false;
        engineConduits.clearRealnameInfo();
        engineConduits.writeAutoLogin(false);
        engineConduits.saveDefaultSmallAccount("");
//        engineConduits.saveCurrentLoginUserTickit("");
//        engineConduits.saveCurrentLoginUserUID("");
        return Integer.MAX_VALUE;
    }



    public int bindPhoneNumber(String cellphoneNumber, String verify, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        BindPhoneReuqestParams params = new BindPhoneReuqestParams(cellphoneNumber, verify);
        params.setGameId(configuration.getGameId());


        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int realName(String name,String id,SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        RealNameReuqestParams params = new RealNameReuqestParams(name,id);
        params.setGameId(configuration.getGameId());
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }


    public int alipayAuth(SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        String uid = engineConduits.readCurrentLoginUserUID();
        AlipayAuthRequestParams params = new AlipayAuthRequestParams();
        params.setGameId(configuration.getGameId());

        return httpEngine.alipayAuth(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int alipayRealname(String code,SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        String uid = engineConduits.readCurrentLoginUserUID();
        AlipayRealnameParams params = new AlipayRealnameParams();
        params.setGameId(configuration.getGameId());

        params.setCode(code);

        return httpEngine.alipayRealname(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int sendPhoneVerifyCode(String verify, String verifyType, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        SendVerifyReuqestParams params = new SendVerifyReuqestParams(verify,verifyType);

        params.setGameId(configuration.getGameId());

        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int modifyPassword(String username, String password, String verify, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        AccountInfosRequestParams params = new AccountInfosRequestParams(username, verify);
        params.setGameId(configuration.getGameId());
        params.setSms_type("get_code_retrieve_password");
        params.setType("retrieve_password");
        return httpEngine.getAccountInfosByPhone(params.getPostUrl(), params, new HttpEngineInterceptor(handler));


//        ModifyPasswordReuqestParams params = new ModifyPasswordReuqestParams(username, password);
//        params.setGameId(configuration.getGameId());
//        params.setVerify(verify);
//
//        return httpEngine.modifyPassword(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int modifyPasswordFinal(String username, String password, String token, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
//        AccountInfosRequestParams params = new AccountInfosRequestParams(username, verify);
//        params.setGameId(configuration.getGameId());
//        params.setSms_type("get_code_retrieve_password");
//        params.setType("retrieve_password");
//        return httpEngine.getAccountInfosByPhone(params.getPostUrl(), params, new HttpEngineInterceptor(handler));


        ModifyPasswordReuqestParams params = new ModifyPasswordReuqestParams(username, password);
        params.setGameId(configuration.getGameId());
        params.setToken(token);

        return httpEngine.modifyPassword(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int getPayChannelInfo(Goods goods, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();
        PayChannelReuqestParams params = new PayChannelReuqestParams(configuration.getGameId());
        params.setCurrency(goods.getGoodsPrice());


        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }



    public int createOrder(String payid,String vercherid, Goods goods, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        CreateOrderRequestParams params = new CreateOrderRequestParams(payid,vercherid, goods);


        params.setGameId(configuration.getGameId());
        params.setPlacement_platform_appid(JuHaoWanSDK.getInstance().getToutiaoAppid());
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int createPlatCoinOrder(String payId,String currency, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        CreatePlatformOrderRequestParams params = new CreatePlatformOrderRequestParams(payId,currency);

        params.setGameId(configuration.getGameId());

        return httpEngine.createPlatCoinOrder(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int platformCoin(Goods goods, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        PlatformCoinRequestParams params = new PlatformCoinRequestParams(goods);
        params.setUid(engineConduits.readCurrentLoginUserUID());

        params.setGameId(configuration.getGameId());

        return httpEngine.platformCoin(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }
    public int platformCoinDetail( SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        PlatformCoinDetailParams params = new PlatformCoinDetailParams();
        params.setUid(engineConduits.readCurrentLoginUserUID());

        params.setGameId(configuration.getGameId());

        return httpEngine.platformCoinDetail(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int checkVersion(SimpleAsyncResponseHandler handler){
        checkEngineInitialization();

        CheckVersionRequestParams params = new CheckVersionRequestParams();
        params.setGameId(configuration.getGameId());
        params.setVersionName(XmlUtils.getChannelGameVersionCode());

        return httpEngine.checkVersion(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int uploadRoleInfo(RoleInfo roleInfo, RoleStatus status, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        RoleInfoRequestParams params = new RoleInfoRequestParams(configuration.getGameId(), roleInfo);


        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int checkOrder(String orderid,String appid, SimpleAsyncResponseHandler handler){
        checkEngineInitialization();
        CheckOrderRequestParams params =new CheckOrderRequestParams(orderid,appid);
        return httpEngine.commenPost(params.getPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int getGameActivityInfo(SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        ActivityRequestParams params = new ActivityRequestParams(configuration.getGameId());

        return httpEngine.getGameActivityInfo(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int getRedPackageInfo(SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        RedpacakgeReuqestParams params = new RedpacakgeReuqestParams();

        params.setRole_id(JuHaoWanSDK.getInstance().getmRoleInfo().getRoleId());
        params.setGameId(configuration.getGameId());
        params.setServer_id(JuHaoWanSDK.getInstance().getmRoleInfo().getServerId());

//        return httpEngine.getRedpackageInfo("http://m.91wansy.com/api/hongbao", params, new HttpEngineInterceptor(handler));
        return httpEngine.getRedpackageInfo(getBaseHttpPostUrl().replace("SdkV3","hongbao"), params, new HttpEngineInterceptor(handler));
    }

    public int goGetRedPackage(String id,SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        RedpacakgeGetReuqestParams params = new RedpacakgeGetReuqestParams();

        params.setRole_id(JuHaoWanSDK.getInstance().getmRoleInfo().getRoleId());
        params.setGameId(configuration.getGameId());
        params.setServer_id(JuHaoWanSDK.getInstance().getmRoleInfo().getServerId());

        params.setHongbao_id(id);

        return httpEngine.getRedpackage(getBaseHttpPostUrl().replace("SdkV3","hongbao"), params, new HttpEngineInterceptor(handler));
//        return httpEngine.getRedpackageInfo(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int redPackageBind(String name,String account,SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        RedpacakgeBindReuqestParams params = new RedpacakgeBindReuqestParams();

        params.setRole_id(JuHaoWanSDK.getInstance().getmRoleInfo().getRoleId());
        params.setGameId(configuration.getGameId());
        params.setServer_id(JuHaoWanSDK.getInstance().getmRoleInfo().getServerId());

        params.setReal_name(name);
        params.setZfb_account(account);

        return httpEngine.redpackageBind(getBaseHttpPostUrl().replace("SdkV3","hongbao"), params, new HttpEngineInterceptor(handler));
//        return httpEngine.getRedpackageInfo(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int redPackageCashOut(String money,SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        RedpacakgeCashOutReuqestParams params = new RedpacakgeCashOutReuqestParams();

        params.setRole_id(JuHaoWanSDK.getInstance().getmRoleInfo().getRoleId());
        params.setGameId(configuration.getGameId());
        params.setServer_id(JuHaoWanSDK.getInstance().getmRoleInfo().getServerId());

        params.setMoney(money);

        return httpEngine.redpackageCashOut(getBaseHttpPostUrl().replace("SdkV3","hongbao"), params, new HttpEngineInterceptor(handler));
//        return httpEngine.getRedpackageInfo(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }



    public int getGamePushInfo(RoleInfo roleInfo, SimpleAsyncResponseHandler handler) {
        checkEngineInitialization();

        PushInfoRequestParams params = new PushInfoRequestParams();
        params.setGameId(configuration.getGameId());

        params.setLastTime(engineConduits.readLastPushTime());
        params.setRoleId(roleInfo.getRoleId());
        params.setServerId(roleInfo.getServerId());

        return httpEngine.getGamePushInfo(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(handler));
    }

    public int reportVideoReward(String advertId, boolean isPlayCompleted, boolean isOwnReward) {
        checkEngineInitialization();
        RewardVideoRequestParams params = new RewardVideoRequestParams();
        params.setGameId(configuration.getGameId());

        params.setAdvertId(advertId);
        params.setVideoCompleted(isPlayCompleted ? 1 : 0);
        params.setVideoReward(isOwnReward ? 1 : 0);
        return httpEngine.reportVideoReward(getBaseHttpPostUrl(), params, new HttpEngineInterceptor(null));
    }


    public String getFloatMenuUrl(String key) {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService(key)
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }
    public String getFloatMenuUrl(NavModel model) {
        StringBuilder builder =new StringBuilder(model.getUrl());
        builder.append("?token=").append(engineConduits.readCurrentLoginUserTicket());
        WL.d(TAG, "toParamsString : " + builder.toString());
        return builder.toString();
    }


    public String getUserHttpRequestUrl() {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService("/user/index")
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }
    public String getActivityHttpRequestUrl() {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService("/activity")
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }

    public String getCustomServiceHttpRequestUrl() {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService("/customer")
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }

    public String getGiftsHttpRequestUrl() {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService("/gift_pack")
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }

    public String getStrategyHttpRequestUrl() {
        GetRequestParams.Builder builder = new GetRequestParams.Builder();
        builder.setService("/strategy")
                .setTicket(engineConduits.readCurrentLoginUserTicket());
        GetRequestParams params = builder.build();
        return params.toParamsString(getBaseHttpGetUrl());
    }
}
